﻿using System;
using NUnit.Framework;

namespace Mirabeau.Web.Session.UnitTests
{
    /// <summary>
    /// Tests for the <see cref="SessionStateDataContainer"/>.
    /// </summary>
    [TestFixture]
    public class SessionStateDataContainerTest
    {
        ///<summary>
        /// Test if all fields are correctly serialized
        ///</summary>
        [Test]
        public void MustSerializeAllFields()
        {
            //Arrange
            SessionStateDataContainer container = new SessionStateDataContainer(new SerializableSessionStateItemCollection(), 30);
            container.IsLocked = true;
            container.LockId = Guid.NewGuid();
            container.LockTime = DateTime.Now;
            container.Timeout = 30;
            container.SessionStateItemCollection["testitem"] = "testvalue";

            //Act
            byte[] serializedData = SerializableSessionStateItemCollectionTest.Serialize(container);
            SessionStateDataContainer deserializedContainer = SerializableSessionStateItemCollectionTest.Deserialize<SessionStateDataContainer>(serializedData);

            //Assert
            Assert.That(container.IsLocked,Is.EqualTo(deserializedContainer.IsLocked));
            Assert.That(container.LockId, Is.EqualTo(deserializedContainer.LockId));
            Assert.That(container.LockTime, Is.EqualTo(deserializedContainer.LockTime));
            Assert.That(container.Timeout, Is.EqualTo(deserializedContainer.Timeout));
            Assert.That(container.SessionStateItemCollection["testitem"], Is.EqualTo(deserializedContainer.SessionStateItemCollection["testitem"]));
        }
    }
}
